﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SCG.SolarVengeance
{
    public partial class BasePage : UserControl
    {
        //constructors
        public BasePage()
        {
            InitializeComponent();
        }

        //Main Form reference
        public MainForm MainForm
        {
            get
            {
                return MainForm.Instance;
            }
        }

        //show/hide controls based on tag value
        public void ShowControls(Control parent, int tag, bool show)
        {
            foreach (Control ctl in parent.Controls)
            {
                bool apply = tag == 0;
                if (!apply)
                {
                    if (ctl.Tag != null)
                    {
                        string s = (string)ctl.Tag;
                        if (s != "")
                        {
                            int ctlTag = Int32.Parse((string)ctl.Tag);
                            apply = ctlTag >= tag;
                        }
                    }
                }
                if (apply)
                    ctl.Visible = show;
            }
        }

        //enable/disable controls based on tag value
        public void EnableControls(Control parent, int tag, bool enable)
        {
            foreach (Control ctl in parent.Controls)
            {
                bool apply = tag == 0;
                if (!apply)
                {
                    if (ctl.Tag != null)
                    {
                        string s = (string)ctl.Tag;
                        if (s != "")
                        {
                            int ctlTag = Int32.Parse((string)ctl.Tag);
                            apply = ctlTag >= tag;
                        }
                    }
                }
                if (apply)
                    ctl.Enabled = enable;
            }
        }

        //set fonts
        private void ucBase_Load(object sender, EventArgs e)
        {
            foreach (Control ctl in Controls)
                SetFont(ctl);
        }
        private void SetFont(Control ctl)
        {
            Font f = new Font(MainForm.FontFamily, ctl.Font.Size, ctl.Font.Style);
            ctl.Font = f;
            foreach (Control child in ctl.Controls)
                SetFont(child);
        }

        //initialization
        public virtual void Initialize()
        {
        }
    }
}
